home *** CD-ROM | disk | FTP | other *** search
- /* $Copyright:
- *
- * Copyright 1998-2000 by the Massachusetts Institute of Technology.
- *
- * All rights reserved.
- *
- * Export of this software from the United States of America may require a
- * specific license from the United States Government. It is the
- * responsibility of any person or organization contemplating export to
- * obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
- * this software and its documentation for any purpose and without fee is
- * hereby granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of M.I.T. not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission. Furthermore if you
- * modify this software you must label your software as modified software
- * and not distribute it in such a fashion that it might be confused with
- * the original MIT software. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Individual source code files are copyright MIT, Cygnus Support,
- * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
- *
- * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
- * and Zephyr are trademarks of the Massachusetts Institute of Technology
- * (MIT). No commercial use of these trademarks may be made without prior
- * written permission of MIT.
- *
- * "Commercial use" means use of a name in a product or other for-profit
- * manner. It does NOT prevent a commercial firm from referring to the MIT
- * trademarks in order to convey information (although in doing so,
- * recognition of their trademark status should be given).
- * $
- */
-
- /* $Header: /cvs/macdev/mit/lib/ErrorLib/ClassicGlue/ErrorLib.glue.c,v 1.3 2001/03/20 02:33:16 meeroh Exp $ */
-
- #include <CodeFragments.h>
- #include <Gestalt.h>
- #include <Errors.h>
-
- #include <KerberosSupport/ErrorLib.h>
- #include "ErrorLib.glue.h"
-
- /* These functions must obey CFM calling conventions. Functions which return
- pointers must return them in D0, not A0 like ThinkC static 68k does. This way
- we can call CFM functions by pointer from here (if they are called by pointer
- then the compiler can't tell ahead of time to do D0->A0 translation because it
- doesn't know what calling convention the functions use).
-
- Note that if it is necessary (if you don't use MPWC calling conventions)
- the D0->A0 translation will be done by the compiler in the places where
- the application calls these glue routines. */
- #pragma d0_pointers on
-
- /* Hardcode library fragment name here */
- #define kLibraryName "\pMIT Support•ErrorLib"
-
- /* Private function prototypes */
-
- static OSErr Find_Symbol(
- Ptr* pSymAddr,
- Str255 pSymName,
- ProcInfoType pProcInfo);
-
- static pascal Boolean HaveCFM(void);
-
- static pascal OSErr GetSystemArchitecture(OSType *archType);
-
-
- /* This code is directly from Technote 1077 */
- /* changed Library name to be hardcoded at the top of the file
- instead in the middle of the code */
-
- /* Private functions */
-
- static pascal OSErr GetSystemArchitecture(OSType *archType)
- {
- static long sSysArchitecture = 0; // static so we only Gestalt once.
- OSErr tOSErr = noErr;
-
- *archType = kAnyCFragArch; // assume wild architecture
-
- // If we don't know the system architecture yet...
- if (sSysArchitecture == 0)
- // ...Ask Gestalt what kind of machine we are running on.
- tOSErr = Gestalt(gestaltSysArchitecture, &sSysArchitecture);
-
- if (tOSErr == noErr) // if no errors
- {
- if (sSysArchitecture == gestalt68k) // 68k?
- *archType = kMotorola68KCFragArch;
- else if (sSysArchitecture == gestaltPowerPC) // PPC?
- *archType = kPowerPCCFragArch;
- else
- tOSErr = gestaltUnknownErr; // who knows what might be next?
- }
- return tOSErr;
- }
-
- static pascal Boolean HaveCFM(void)
- {
- long response;
- return ( (Gestalt (gestaltCFMAttr, &response) == noErr) &&
- (((response >> gestaltCFMPresent) & 1) != 0));
- }
-
- static OSErr Find_Symbol(
- Ptr* pSymAddr,
- Str255 pSymName,
- ProcInfoType pProcInfo)
- {
- static CFragConnectionID sCID = 0;
- static OSType sArchType = kAnyCFragArch;
- static OSErr sOSErr = noErr;
-
- Str255 errMessage;
- Ptr mainAddr;
- CFragSymbolClass symClass;
- ISAType tISAType;
-
- if (sArchType == kAnyCFragArch) // if architecture is undefined...
- {
- sCID = 0; // ...force (re)connect to library
- sOSErr = GetSystemArchitecture(&sArchType); // determine architecture
- if (sOSErr != noErr)
- return sOSErr; // OOPS!
- }
-
- if (!HaveCFM()) {
- // If we don't have CFM68K, return a reasonable-looking error.
- sOSErr = cfragLibConnErr;
- return sOSErr;
- }
-
- if (sArchType == kMotorola68KCFragArch) // ...for CFM68K
- tISAType = kM68kISA | kCFM68kRTA;
- else if (sArchType == kPowerPCCFragArch) // ...for PPC CFM
- tISAType = kPowerPCISA | kPowerPCRTA;
- else
- sOSErr = gestaltUnknownErr; // who knows what might be next?
-
- if (sCID == 0) // If we haven't connected to the library yet...
- {
- // NOTE: The library name is hard coded here.
- // I try to isolate the glue code, one file per library.
- // I have had developers pass in the Library name to allow
- // plug-in type support. Additional code has to be added to
- // each entry points glue routine to support multiple or
- // switching connection IDs.
- sOSErr = GetSharedLibrary(kLibraryName, sArchType, kLoadCFrag,
- &sCID, &mainAddr, errMessage);
- if (sOSErr != noErr)
- return sOSErr; // OOPS!
- }
-
- // If we haven't looked up this symbol yet...
- if ((Ptr) *pSymAddr == (Ptr) kUnresolvedCFragSymbolAddress)
- {
- // ...look it up now
- sOSErr = FindSymbol(sCID,pSymName,pSymAddr,&symClass);
- if (sOSErr != noErr) // in case of error...
- // ...clear the procedure pointer
- *(Ptr*) &pSymAddr = (Ptr) kUnresolvedCFragSymbolAddress;
- # if !GENERATINGCFM // if this is classic 68k code...
- *pSymAddr = (Ptr)NewRoutineDescriptorTrap((ProcPtr) *pSymAddr,
- pProcInfo, tISAType); // ...create a routine descriptor...
- # endif
- }
- return sOSErr;
- }
-
-
- /* CFM Glue Code for exported functions! */
-
- /**** GetMITLibError ****/
- /* OSStatus GetMITLibError(void); */
-
- enum {
- GetMITLibError_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
-
- };
-
-
- typedef OSStatus (*GetMITLibError_ProcPtrType)(void);
- OSStatus GetMITLibError (void)
- {
- static GetMITLibError_ProcPtrType GetMITLibError_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetMITLibError_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetMITLibError_ProcPtr, "\pGetMITLibError", GetMITLibError_ProcInfo);
- if((Ptr) GetMITLibError_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetMITLibError_ProcPtr();
- }
-
-
- /**** SetMITLibError ****/
- /* void SetMITLibError(OSStatus theError); */
-
- enum {
- SetMITLibError_ProcInfo = kThinkCStackBased
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- };
-
-
- typedef void (*SetMITLibError_ProcPtrType)(OSStatus);
- void SetMITLibError (OSStatus theError)
- {
- static SetMITLibError_ProcPtrType SetMITLibError_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) SetMITLibError_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &SetMITLibError_ProcPtr, "\pSetMITLibError", SetMITLibError_ProcInfo);
- if((Ptr) SetMITLibError_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- SetMITLibError_ProcPtr(theError);
- }
-
-
- /**** ClearMITLibError ****/
- /* void ClearMITLibError(void); */
-
- enum {
- ClearMITLibError_ProcInfo = kThinkCStackBased
-
- };
-
-
- typedef void (*ClearMITLibError_ProcPtrType)(void);
- void ClearMITLibError (void)
- {
- static ClearMITLibError_ProcPtrType ClearMITLibError_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) ClearMITLibError_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &ClearMITLibError_ProcPtr, "\pClearMITLibError", ClearMITLibError_ProcInfo);
- if((Ptr) ClearMITLibError_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- ClearMITLibError_ProcPtr();
- }
-
-
- /**** RegisterErrorTable ****/
- /* OSStatus RegisterErrorTable(const FSSpec* inResFile, SInt16 inResID); */
-
- enum {
- RegisterErrorTable_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(const FSSpec *)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SInt16)))
- };
-
-
- typedef OSStatus (*RegisterErrorTable_ProcPtrType)(const FSSpec *, SInt16);
- OSStatus RegisterErrorTable (const FSSpec * inResFile,
- SInt16 inResID)
- {
- static RegisterErrorTable_ProcPtrType RegisterErrorTable_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) RegisterErrorTable_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &RegisterErrorTable_ProcPtr, "\pRegisterErrorTable", RegisterErrorTable_ProcInfo);
- if((Ptr) RegisterErrorTable_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return RegisterErrorTable_ProcPtr(inResFile, inResID);
- }
-
-
- /**** GetErrorLongFormat ****/
- /* OSStatus GetErrorLongFormat(OSStatus error, char *message, long messageLength); */
-
- enum {
- GetErrorLongFormat_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- };
-
-
- typedef OSStatus (*GetErrorLongFormat_ProcPtrType)(OSStatus, char *, long);
- OSStatus GetErrorLongFormat (OSStatus error,
- char * message,
- long messageLength)
- {
- static GetErrorLongFormat_ProcPtrType GetErrorLongFormat_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetErrorLongFormat_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetErrorLongFormat_ProcPtr, "\pGetErrorLongFormat", GetErrorLongFormat_ProcInfo);
- if((Ptr) GetErrorLongFormat_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetErrorLongFormat_ProcPtr(error, message, messageLength);
- }
-
-
- /**** GetErrorShortFormat ****/
- /* OSStatus GetErrorShortFormat(OSStatus error, char *message, long messageLength); */
-
- enum {
- GetErrorShortFormat_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- };
-
-
- typedef OSStatus (*GetErrorShortFormat_ProcPtrType)(OSStatus, char *, long);
- OSStatus GetErrorShortFormat (OSStatus error,
- char * message,
- long messageLength)
- {
- static GetErrorShortFormat_ProcPtrType GetErrorShortFormat_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetErrorShortFormat_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetErrorShortFormat_ProcPtr, "\pGetErrorShortFormat", GetErrorShortFormat_ProcInfo);
- if((Ptr) GetErrorShortFormat_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetErrorShortFormat_ProcPtr(error, message, messageLength);
- }
-
-
- /**** GetErrorManager ****/
- /* OSStatus GetErrorManager(OSStatus error, char *message, long messageLength); */
-
- enum {
- GetErrorManager_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- };
-
-
- typedef OSStatus (*GetErrorManager_ProcPtrType)(OSStatus, char *, long);
- OSStatus GetErrorManager (OSStatus error,
- char * message,
- long messageLength)
- {
- static GetErrorManager_ProcPtrType GetErrorManager_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetErrorManager_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetErrorManager_ProcPtr, "\pGetErrorManager", GetErrorManager_ProcInfo);
- if((Ptr) GetErrorManager_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetErrorManager_ProcPtr(error, message, messageLength);
- }
-
-
- /**** GetErrorShortString ****/
- /* OSStatus GetErrorShortString(OSStatus error, char *message, long messageLength); */
-
- enum {
- GetErrorShortString_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- };
-
-
- typedef OSStatus (*GetErrorShortString_ProcPtrType)(OSStatus, char *, long);
- OSStatus GetErrorShortString (OSStatus error,
- char * message,
- long messageLength)
- {
- static GetErrorShortString_ProcPtrType GetErrorShortString_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetErrorShortString_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetErrorShortString_ProcPtr, "\pGetErrorShortString", GetErrorShortString_ProcInfo);
- if((Ptr) GetErrorShortString_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetErrorShortString_ProcPtr(error, message, messageLength);
- }
-
-
- /**** GetErrorLongString ****/
- /* OSStatus GetErrorLongString(OSStatus error, char *message, long messageLength); */
-
- enum {
- GetErrorLongString_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- };
-
-
- typedef OSStatus (*GetErrorLongString_ProcPtrType)(OSStatus, char *, long);
- OSStatus GetErrorLongString (OSStatus error,
- char * message,
- long messageLength)
- {
- static GetErrorLongString_ProcPtrType GetErrorLongString_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetErrorLongString_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetErrorLongString_ProcPtr, "\pGetErrorLongString", GetErrorLongString_ProcInfo);
- if((Ptr) GetErrorLongString_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetErrorLongString_ProcPtr(error, message, messageLength);
- }
-
-
- /**** GetErrorString ****/
- /* OSStatus GetErrorString(OSStatus error, char *message, long messageLength, ErrorFormat format); */
-
- enum {
- GetErrorString_ProcInfo = kThinkCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(OSStatus)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(ErrorFormat)))
- };
-
-
- typedef OSStatus (*GetErrorString_ProcPtrType)(OSStatus, char *, long, ErrorFormat);
- OSStatus GetErrorString (OSStatus error,
- char * message,
- long messageLength,
- ErrorFormat format)
- {
- static GetErrorString_ProcPtrType GetErrorString_ProcPtr = kUnresolvedCFragSymbolAddress;
-
- // if this symbol has not been setup yet...
- if((Ptr) GetErrorString_ProcPtr == (Ptr) kUnresolvedCFragSymbolAddress)
- Find_Symbol((Ptr *) &GetErrorString_ProcPtr, "\pGetErrorString", GetErrorString_ProcInfo);
- if((Ptr) GetErrorString_ProcPtr != (Ptr) kUnresolvedCFragSymbolAddress)
- return GetErrorString_ProcPtr(error, message, messageLength, format);
- }
-
-
- Boolean ErrorLibraryIsPresent(void)
- {
- Ptr symAddr;
- return (Find_Symbol (&symAddr, "\pGetMITLibError", GetMITLibError_ProcInfo)) == noErr;
- }
-
-